var app = getApp();

Page({
    data: {
        _is_load: !0,
        is_akey: !1
    },
    onLoad: function(a) {
        var n = this, t = a.id;
        app.util.getUserInfo(function(a) {
            n.setData({
                userInfo: a
            });
        }), app.util.request({
            url: "entry/wxapp/Setup",
            data: {
                m: "bbyscm_card"
            },
            success: function(a) {
                n.setData({
                    setup: a.data.data
                });
            }
        }), app.util.request({
            url: "entry/wxapp/GetCard",
            data: {
                m: "bbyscm_card"
            },
            success: function(a) {
                0 == a.data.errno && (a.data.data ? n.setData({
                    my_card_info: a.data.data
                }) : wx.showModal({
                    title: "提示",
                    content: "你还没有创建名片，不能使用分会功能",
                    confirmText: "创建名片",
                    success: function(a) {
                        a.confirm ? wx.navigateTo({
                            url: "../../card/edit/card-edit"
                        }) : a.cancel && wx.navigateBack();
                    }
                }));
            }
        }), t ? app.util.request({
            url: "entry/wxapp/GetCardTr",
            data: {
                m: "bbyscm_card",
                card_id: t
            },
            success: function(a) {
                n.setData({
                    card_info: a.data.data,
                    _is_load: !1
                });
            }
        }) : wx.chooseImage({
            count: 1,
            sizeType: [ "original", "compressed" ],
            sourceType: [ "album", "camera" ],
            success: function(a) {
                var t = a.tempFilePaths;
                wx.showToast({
                    title: "正在上传...",
                    icon: "loading",
                    duration: 1e4
                });
                var e = app.util.url("entry/wxapp/WxUpload");
                wx.uploadFile({
                    url: e + "m=bbyscm_card",
                    filePath: t[0],
                    name: "file",
                    formData: {},
                    success: function(a) {
                        var t = a.data;
                        "string" == typeof t && (t = JSON.parse(t.trim())), 0 == t.errno ? app.util.request({
                            url: "entry/wxapp/PostTap_scanner",
                            data: {
                                m: "bbyscm_card",
                                img: t.data,
                                cardid: n.data.my_card_info.id
                            },
                            method: "POST",
                            success: function(a) {
                                console.log("返回3", a), a.data.data.id ? wx.navigateTo({
                                    url: "../info/info?card_id=" + a.data.data.id
                                }) : wx.showModal({
                                    title: "提示",
                                    content: "识别失败！",
                                    showCancel: !1,
                                    success: function() {
                                        wx.navigateBack();
                                    }
                                });
                            }
                        }) : wx.showToast({
                            title: t.message,
                            icon: "success",
                            duration: 2e3
                        });
                    },
                    complete: function() {
                        wx.hideToast();
                    }
                });
            }
        });
    },
    postCard: function(a) {
        var t = this;
        t.setData({
            btn_disabled: !0,
            submitIsLoading: !0
        }), JSON.stringify(a.detail.value);
        var e = a.detail.formId, n = t.data.card_info.id, o = a.detail.value.mobile, i = a.detail.value.mobile2, s = a.detail.value.cardname, c = a.detail.value.job, d = a.detail.value.email, r = a.detail.value.company, u = a.detail.value.address;
        if (!n) return wx.showModal({
            title: "提示",
            content: "获取信息失败",
            showCancel: !1,
            success: function(a) {
                a.confirm, t.setData({
                    btn_disabled: !1,
                    submitIsLoading: !1
                });
            }
        }), !1;
        wx.showToast({
            title: "提交中...",
            icon: "loading",
            duration: 1e4
        }), app.util.request({
            url: "entry/wxapp/PostCardA",
            data: {
                m: "bbyscm_card",
                form_id: e,
                cardid: n,
                mobile: o,
                mobile2: i,
                cardname: s,
                job: c,
                email: d,
                company: r,
                address: u
            },
            method: "POST",
            success: function(a) {
                0 == a.data.errno ? wx.showModal({
                    title: "提示",
                    content: "提交成功",
                    showCancel: !1,
                    success: function(a) {
                        wx.navigateBack();
                    }
                }) : wx.showModal({
                    title: "提示",
                    content: a.data.message,
                    showCancel: !1,
                    success: function(a) {
                        a.confirm;
                    }
                });
            },
            fail: function(a) {
                wx.showModal({
                    title: "提示",
                    content: a.data.message,
                    showCancel: !1,
                    success: function(a) {
                        a.confirm;
                    }
                });
            },
            complete: function() {
                wx.hideToast();
            }
        });
    },
    onReady: function() {},
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    onShareAppMessage: function() {}
});